#!/bin/sh

app=$1
tag=$2
echo $app
echo $tag

if [ ! $app ]; then
    echo "app is null"
else
    echo "========stop========"
    docker ps -a | grep "$app" | awk '{print $1 }'|xargs docker stop
    docker ps -a | grep "$app" | awk '{print $1 }'|xargs docker rm -f
    docker images| grep "$app" | awk '{print $3 }'|xargs docker rmi
    echo "========build========"
    #cd /data/jenkins-data/workspace/$app@2/
    cd ../$app@2/
    pwd
    docker build -t $app:$tag .
    echo "========start========"
    docker run --add-host=hycloud-gateway:86.12.74.57 -d -p 80:80 --name=$app $app:$tag
fi
